using System.Collections.Generic;
using System.Linq;
using TaskKernel.Domain.Services.Role;

namespace TaskKernel.Domain.Services.Permission
{
    public class TaskPermissions
    {
        private readonly ICollection<IPermission<TaskPermissions>> _permissions;

        public TaskPermissions(RoleEnum role, Task task)
        {
            _permissions = new List<IPermission<TaskPermissions>>();
            Role = role;
            Task = task;
        }

        public RoleEnum Role { get; protected set; }
        public Task Task { get; private set; }

        public virtual void AddPermissions(IPermission<TaskPermissions> permissions)
        {
            _permissions.Add(permissions);
        }

        public virtual Permissions GetPermissions()
        {
            foreach (var permission in _permissions)
            {
                Permissions permissions = permission.GetPermissions(this);
                if (!permissions.GetType().Equals(new Permissions().GetType()))
                    return permissions;
            }
            return new Permissions();
        }
    }
}